document.ready(function() {
    setValue('menuid', getUrlParam('menuid'));
    queryKey('ok', 'yes');
});

function queryKey(flag, permission = 'no') {
    openLoad();

    var param = {};
    param.ctrl = 'housecraft';
    param.func = 'getHousecraftInfo';
    param.housecraftid = getUrlParam('housecraftid');
    param.menuid = getAjaxValue('menuid');
    param.permission = permission;

    sendAjax(param, function(result) {
        housecraft.info = result.housecraftInfo;

        if (result.permission != null && result.permission != '') {
            housecraft.permission = result.permission;
        }

        setDisplay('mainBg', '');
        closeLoad();
    });
}

function back() {
    parent.closeSlipIframeDiv();
}

function openMap(position) {
    window.open('admin.php?m=housecraft&c=map&position=' + position);
}

function putHousecraft(id) {
    openConfirm('确定发布吗？', null, function() {
        var param = {};
        param.ctrl = 'housecraft';
        param.func = 'putHousecraft';
        param.housecraftid = getAjaxValue('housecraftid');

        sendAjax(param, function(result) {
            submitRecord('edit', '家政服务查看页', '发布', getValue('housecraftid'));
            parent.closeSlipIframeDiv();
            parent.queryKey('page');
        });
    });
}

function retrieveHousecraft(id) {
    openConfirm('确定回收吗？', null, function() {
        var param = {};
        param.ctrl = 'housecraft';
        param.func = 'retrieveHousecraft';
        param.housecraftid = getAjaxValue('housecraftid');

        sendAjax(param, function(result) {
            submitRecord('edit', '家政服务查看页', '回收', getValue('housecraftid'));
            parent.closeSlipIframeDiv();
            parent.queryKey('page');
        });
    });
}

function pullHousecraft(id) {
    openConfirm('确定下架吗？', null, function() {
        var param = {};
        param.ctrl = 'housecraft';
        param.func = 'pullHousecraft';
        param.housecraftid = getAjaxValue('housecraftid');

        sendAjax(param, function(result) {
            submitRecord('edit', '家政服务查看页', '下架', getValue('housecraftid'));
            parent.closeSlipIframeDiv();
            parent.queryKey('page');
        });
    });
}

function restoreHousecraft(id) {
    openConfirm('确定恢复吗？', null, function() {
        var param = {};
        param.ctrl = 'housecraft';
        param.func = 'restoreHousecraft';
        param.housecraftid = getAjaxValue('housecraftid');

        sendAjax(param, function(result) {
            submitRecord('edit', '家政服务查看页', '恢复', getValue('housecraftid'));
            parent.closeSlipIframeDiv();
            parent.queryKey('page');
        });
    });
}

function openAlbum(index, title, picList) {
    parent.parent.openAlbum(index, title, picList);
}

function openBigPic(title, path) {
    parent.parent.openBigPic(title, path);
}